<template>
	<el-card>
		<div slot="header" class="clearfix">
			<!--工具条-->
			<el-form :inline="true" :model="filters" class="filter-form-box">
				<el-form-item style="margin-right: 0;">
					<el-button size="mini" v-on:click="isShowAdvancedSearch=!isShowAdvancedSearch" title="高级搜索">
						<i class="el-icon-plus" v-show="!isShowAdvancedSearch"></i>
						<i class="el-icon-minus" v-show="isShowAdvancedSearch"></i>
					</el-button>
				</el-form-item>
				<el-form-item style="margin-right: 0;">
					<el-button size="mini" v-on:click="refreshFilters" title="重置"><i class="el-icon-refresh"></i></el-button>
				</el-form-item>
				<el-form-item>
					<el-button size="mini" v-on:click="getData" title="搜索"><i class="el-icon-search"></i></el-button>
				</el-form-item>
				<el-form-item style="float: right">
					<el-button type="primary" size="small" @click="handleAdd">新增</el-button>
				</el-form-item>
			</el-form>
			<el-form v-show='isShowAdvancedSearch' :inline="true" :model="filters" class="filter-form-box advanced-search-form">
				<el-form-item>
					<el-date-picker
							size="small"
							v-model="filters.classYear"
							type="year"
							value-format="yyyy"
							placeholder="选择年级"
							@input="filtersClassYearChange()">
					</el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-select size="small" v-model="filters.departmentId" filterable placeholder="请选择院系" @input="departmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-select size="small" v-model="filters.specialtyId" filterable placeholder="请选择专业" :disabled="!isSelectDepartment" @input="specialtyIdChange">
						<el-option
								v-for="item in specialtyList"
								v-if="item.departmentId === filters.departmentId"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-select size="small" v-model="filters.classId" filterable placeholder="请选择班级" :disabled="!isSelectSpecialty">
						<el-option
								v-for="item in classList"
								:key="item.id"
								:label="item.year+'级'+item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
		</div>
		<!--列表-->
		<el-table stripe border :data="datas" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="classYear" label="关联的年级" sortable>
			</el-table-column>
			<el-table-column prop="className" label="关联的班级" sortable>
			</el-table-column>
			<el-table-column prop="courseName" label="关联的课程" sortable>
			</el-table-column>
			<el-table-column prop="teacherName" label="授课老师" sortable>
			</el-table-column>
			<el-table-column prop="year" label="授课学年" sortable>
			</el-table-column>
			<el-table-column prop="semester" label="授课学期" sortable>
			</el-table-column>
			<el-table-column prop="remark" label="备注" sortable>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template slot-scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
                </template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!--编辑界面-->
		<el-dialog title="编辑信息" :loading="isEditLoading" :visible.sync="editFormVisible"  :close-on-click-modal="false" :before-close="closeEditDialog">
			<el-form class="relevancy-form-box"  :model="editData" label-width="80px" :rules="editFormRules" ref="editData">
				<el-form-item label="关联班级" prop="classId">
					<el-select v-model="editData.departmentId" filterable placeholder="请选择院系" @input="classDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="editData.specialtyId" placeholder="请选择专业" filterable :disabled="!isSelectClassDepartment" @input="classSpecialtyIdChange">
						<el-option
								v-for="item in specialtyList"
								v-if="item.departmentId === editData.departmentId"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-date-picker
							v-model="editData.classYear"
							type="year"
							value-format="yyyy"
							:disabled="!isSelectClassSpecialty"
							placeholder="请选择班级年级"
							@input="classYearChange(1)">
					</el-date-picker>
					<el-select v-model="editData.classId" placeholder="请选择班级" filterable :disabled="!isSelectClassYear">
						<el-option
								v-for="item in classList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="关联课程" prop="courseId">
					<el-select v-model="editCourseDepartmentId" filterable placeholder="请选择院系" @input="courseDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="editCourseSpecialtyId" placeholder="请选择专业" filterable :disabled="!isSelectCourseDepartment" @input="courseSpecialtyIdChange(1)">
						<el-option
								v-for="item in specialtyList"
								v-if="item.departmentId === editCourseDepartmentId"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="editData.courseId" placeholder="请选择课程" filterable :disabled="!isSelectCourseSpecialty">
						<el-option
								v-for="item in courseList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="授课教师" prop="teacherId">
					<el-select v-model="editTeacherDepartmentId" filterable placeholder="请选择院系" @input="teacherDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="editData.teacherId" placeholder="输入搜索并选择授课教师" filterable :disabled="!isSelectTeacherDepartment">
						<el-option
								v-for="item in teacherList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="授课学期">
					<el-select v-model="editData.year" filterable placeholder="请选择院系">
						<el-option
								v-for="item in filterRelevancyTimeYear"
								:key="item"
								:label="item"
								:value="item">
						</el-option>
					</el-select>
					<el-select v-model="editData.semester" placeholder="输入搜索并选择授课教师">
						<el-option
								v-for="item in 3"
								:key="item"
								:label="item"
								:value="item">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="备注">
					<el-input type="textarea" v-model="formData.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" size="small" @click.native="saveSubmit(2)" :loading="saveLoading">保存</el-button>
			</div>
		</el-dialog>

		<!--新增界面-->
		<el-dialog title="新增信息" :visible.sync="addFormVisible" :close-on-click-modal="false" :before-close="closeAddDialog">
			<el-form class="relevancy-form-box" :model="formData" label-width="80px" :rules="addFormRules" ref="formData">
				<el-form-item label="关联班级" prop="relevancyClass.classId">
					<el-select v-model="formData.relevancyClass.departmentId" filterable placeholder="请选择院系" @input="classDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="formData.relevancyClass.specialtyId" placeholder="请选择专业" filterable :disabled="!isSelectClassDepartment" @input="classSpecialtyIdChange">
						<el-option
								v-for="item in specialtyList"
								v-if="item.departmentId === formData.relevancyClass.departmentId"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-date-picker
							v-model="formData.relevancyClass.year"
							type="year"
							value-format="yyyy"
							:disabled="!isSelectClassSpecialty"
							placeholder="请选择班级年级"
							@input="classYearChange(2)">
					</el-date-picker>
					<el-select v-model="formData.relevancyClass.classId" placeholder="请选择班级" filterable :disabled="!isSelectClassYear">
						<el-option
								v-for="item in classList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="关联课程" prop="relevancyCourse.courseId">
					<el-select v-model="formData.relevancyCourse.departmentId" filterable placeholder="请选择院系" @input="courseDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="formData.relevancyCourse.specialtyId" placeholder="请选择专业" filterable :disabled="!isSelectCourseDepartment" @input="courseSpecialtyIdChange(2)">
						<el-option
								v-for="item in specialtyList"
								v-if="item.departmentId === formData.relevancyCourse.departmentId"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="formData.relevancyCourse.courseId" placeholder="请选择课程" filterable :disabled="!isSelectCourseSpecialty">
						<el-option
								v-for="item in courseList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="授课教师" prop="relevancyTeacher.teacherId">
					<el-select v-model="formData.relevancyTeacher.departmentId" filterable placeholder="请选择院系" @input="teacherDepartmentIdChange">
						<el-option
								v-for="item in departmentList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
					<el-select v-model="formData.relevancyTeacher.teacherId" placeholder="输入搜索并选择授课教师" filterable :disabled="!isSelectTeacherDepartment">
						<el-option
								v-for="item in teacherList"
								:key="item.id"
								:label="item.name"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="授课学期" prop="relevancyTime.year">
					<el-select v-model="formData.relevancyTime.year" filterable placeholder="请选择学年">
						<el-option
								v-for="item in filterRelevancyTimeYear"
								:key="item"
								:label="item"
								:value="item">
						</el-option>
					</el-select>
					<el-select v-model="formData.relevancyTime.semester" placeholder="请选择学期">
						<el-option
								v-for="item in 3"
								:key="item"
								:label="item"
								:value="item">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="备注">
					<el-input type="textarea" v-model="formData.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" size="small" @click.native="saveSubmit(1)" :loading="saveLoading">提交</el-button>
			</div>
		</el-dialog>
	</el-card>
</template>

<script>
  import {
    getDepartmentList,
    getSpecialtyList,
    getClassList,
    getCourseList,
    searchCourseData,
    getTeacherList,
    searchUserData,
    getRelevancyList,
    removeRelevancyData,
    saveRelevancyData
  } from '../../api/api';

  export default {
    data() {
      return {
        newYear: '',

        filters: {
          departmentId:'',
          specialtyId: '',
          classId: '',
          courseId: '',
          year: '',
          classYear: '',
          teacherId: '',
          semester: '',
        },

        isShowAdvancedSearch: false,
        isSelectDepartment: false,
        isSelectSpecialty: false,

        isSelectClassDepartment: false,
        isSelectClassSpecialty: false,
        isSelectClassYear: false,

        isSelectCourseDepartment: false,
        isSelectCourseSpecialty: false,

        isSelectTeacherDepartment: false,

        datas: [],
        departmentList: [],
        specialtyList: [],
        classList: [],
        courseList: [],
        teacherList: [],

        total: 0,
        page: 0,

        listLoading: false,
        sels: [],//列表选中列

        formType:'',
        editFormVisible: false,//新增界面是否显示
        addFormVisible: false,//新增界面是否显示
        saveLoading: false,
        isEditLoading: false,

        editFormRules: {
          classId: [
            {required: true, message: '请选择需要关联的班级', trigger: 'blur'}
          ],
          courseId: [
            {required: true, message: '请选择需要关联的课程', trigger: 'blur'}
          ],
          teacherId: [
            {required: true, message: '请选择需要关联的授课教师', trigger: 'blur'}
          ],
          year: [
            {required: true, message: '请选择授课学期', trigger: 'blur'}
          ]
        },

        addFormRules: {
          relevancyClass: {
            classId: [
              {required: true, message: '请选择需要关联的班级', trigger: 'blur'}
            ],
          },
          relevancyCourse: {
            courseId: [
              {required: true, message: '请选择需要关联的课程', trigger: 'blur'}
            ],
          },
          relevancyTeacher: {
            teacherId: [
              {required: true, message: '请选择需要关联的授课教师', trigger: 'blur'}
            ]
          },
          relevancyTime: {
            year: [
              {required: true, message: '请选择授课学期', trigger: 'blur'}
            ]
          },
        },
        //编辑界面数据
        editData: [],
        editCourseDepartmentId:'',
        editCourseSpecialtyId:'',
        editTeacherDepartmentId:'',


        //新增界面数据
        formData: {
          relevancyClass:{
            departmentId:'',
            specialtyId:'',
            year: '',
            classId:''
          },
          relevancyCourse:{
            departmentId:'',
            specialtyId:'',
            courseId:''
          },
          relevancyTeacher:{
            departmentId:'',
            teacherId:''
          },
          relevancyTime:{
            semester: '1',
            year: '',
          },
          remark: ''
        }
      }
    },
    computed: {
      filterRelevancyTimeYear: function () {
        let newYear = this.newYear;
        let arr = [];
        for(let i=0; i<10; i++){
          let val1 = newYear-i+1;
          let val2 = newYear-i+2;
          arr.push(val1+'-'+val2)
        }
        return arr;
      }
    },
    methods: {
      handleCurrentChange(val) {
        this.page = val;
        this.getData();
      },

      filtersClassYearChange(){
        this.filters.classId = '',
        this.getClassData(this.filters.classYear,this.filters.departmentId, this.filters.specialtyId);
      },

      closeEditDialog(){
        this.isSelectDepartment = false;
        this.isSelectSpecialty = false;
        this.editFormVisible = false;
        this.refreshFilters();
      },

      closeAddDialog(){
        this.isSelectDepartment = false;
        this.isSelectSpecialty = false;
        this.addFormVisible = false;
        this.refreshFilters();
      },

      departmentIdChange(){
        this.isSelectDepartment = true;
        this.isSelectSpecialty = false;
        this.filters.specialtyId = '';
        this.formData.specialtyId = '';
      },

      classDepartmentIdChange(){
        this.isSelectClassDepartment = true;
        this.isSelectClassSpecialty = false;
        this.isSelectClassYear = false;
        this.editData.specialtyId = '';
        this.formData.relevancyClass.specialtyId = '';
        this.editData.classId = '';
        this.formData.relevancyClass.classId = '';
        this.formData.relevancyClass.year = '';
        this.editData.classYear = '';
      },

      courseDepartmentIdChange(){
        this.isSelectCourseDepartment = true;
        this.isSelectCourseSpecialty = false;
        this.editCourseSpecialtyId = '';
        this.formData.relevancyCourse.specialtyId = '';
        this.editData.courseId = '';
        this.formData.relevancyCourse.courseId = '';
      },

      teacherDepartmentIdChange(val){
        this.isSelectTeacherDepartment = true;
        this.editData.teacherId = '';
        this.formData.relevancyTeacher.teacherId = '';
        this.getTeacherData(val);
      },

      specialtyIdChange(val) {
        this.isSelectSpecialty = true;
        this.filters.classId = '';
        this.getClassData(this.filters.classYear,this.filters.departmentId, val);
      },

      classSpecialtyIdChange() {
        this.isSelectClassSpecialty = true;
        this.isSelectClassYear = false;
        this.formData.relevancyClass.classId = '';
        this.editData.classId = '';
        this.formData.relevancyClass.year = '';
        this.editData.classYear = '';
      },

      courseSpecialtyIdChange(val){
        this.isSelectCourseSpecialty = true;
        this.formData.relevancyCourse.courseId = '';
        if(val===1){
          this.getCourseData(this.editCourseDepartmentId, this.editCourseSpecialtyId);
        }else if(val===2){
          this.getCourseData(this.formData.relevancyCourse.departmentId, this.formData.relevancyCourse.specialtyId);
        }
      },

      classYearChange(val) {
        this.isSelectClassYear = true;
        if(val===1){
          this.getClassData(this.editData.classYear,this.editData.departmentId, this.editData.specialtyId);
        }else if(val===2){
          this.getClassData(this.formData.relevancyClass.year,this.formData.relevancyClass.departmentId, this.formData.relevancyClass.specialtyId);
        }
      },

      //重置搜索条件
      refreshFilters(){
        this.filters = {
          departmentId:'',
          specialtyId: '',
          classId: '',
          courseId: '',
          year: '',
          classYear: '',
          teacherId: '',
          semester: '',
        };
        this.getData();
      },

      //获取数据列表
      getData() {
        let para = {
          count: 10,
          pageNo: this.page,
          sortDirection: 'asc',
          sortField: ["name"],
          departmentId: this.filters.departmentId,
          specialtyId: this.filters.specialtyId,
          classYear: this.filters.classYear,
          classId: this.filters.classId,
          courseId: this.filters.courseId,
          year: this.filters.year,
          teacherId: this.filters.teacherId,
          semester: this.filters.semester,
        };
        if(this.filters.select === '1'){
          para.schoolNumber = this.filters.content;
        }else if(this.filters.select === '2'){
          para.name = this.filters.content;
        }
        console.log(para);
        this.listLoading = true;
        getRelevancyList(para).then((res) => {
          console.log(res);
          this.total = res.data.data.totalPages;
          this.datas = res.data.data.content;
          this.listLoading = false;
        });
      },
      //获取院系数据
      getDepartmentData(){
        let para = {
          count: 100000,
          pageNo: 0,
          sortDirection: 'asc',
          sortField: ["name"],
          name: '',
        };
        getDepartmentList(para).then((res) => {
          this.departmentList = res.data.data.content;
        });
      },
      //获取专业数据
      getSpecialtyData(){
        let para = {
          count: 100000,
          pageNo: 0,
          sortDirection: 'asc',
          sortField: ["name"],
          name: '',
          departmentId: '',
        };
        getSpecialtyList(para).then((res) => {
          this.specialtyList = res.data.data.content;
        });
      },
      //获取班级数据
      getClassData(val1,val2,val3) {
        let para = {
          count: 10000,
          pageNo: 0,
          sortDirection: 'asc',
          sortField: ["name"],
          name: '',
          year: val1 || '',
          departmentId: val2,
          specialtyId: val3,
        };
        console.log(para);
        getClassList(para).then((res) => {
          this.classList = res.data.data.content;
          if(res.data.data.content.length > 0){
            this.formData.relevancyClass.classId = res.data.data.content[0]['id'];
          }else{
            this.formData.relevancyClass.classId = '';
          }
        });
      },
      //获取课程数据
      getCourseData(val1, val2) {
        let para = {
          count: 1000000,
          pageNo: this.page,
          sortDirection: 'asc',
          sortField: ["name"],
          name: '',
          departmentId: val1,
          specialtyId: val2,
        };
        getCourseList(para).then((res) => {
          this.courseList = res.data.data.content || '';
        });
      },
      //获取教师数据
      getTeacherData(val) {
        let para = {
          count: 100000,
          pageNo: this.page,
          sortDirection: 'asc',
          sortField: ["name"],
          classId: '',
          specialtyId: '',
          name: '',
          schoolNumber: '',
          departmentId: val,
          entranceYear: '',
        };
        getTeacherList(para).then((res) => {
          this.teacherList = res.data.data.content;
        });
      },
      //获取对应课程数据
      getSearchCourseData(val) {
        searchCourseData(val).then((res) => {
          console.log(res);
          this.editCourseDepartmentId = res.data.data.departmentId;
          this.editCourseSpecialtyId = res.data.data.specialtyId;
          this.getCourseData(res.data.data.departmentId, res.data.data.specialtyId);
          this.isEditLoading = false;
        });
      },
      //获取对应教师数据
      getSearchUserData(val) {
        searchUserData(val).then((res) => {
          console.log(res);
          this.editTeacherDepartmentId = res.data.data.departmentId;
          this.getTeacherData(res.data.data.departmentId);
        });
      },

      //显示编辑界面
      handleEdit: function (index, row) {
        this.editFormVisible = true;
        this.isSelectClassDepartment = true;
        this.isSelectClassSpecialty = true;
        this.isSelectClassYear = true;
        this.isSelectCourseDepartment = true;
        this.isSelectCourseSpecialty = true;
        this.isSelectTeacherDepartment = true;
        this.isEditLoading = true;
        this.editData = Object.assign({}, row);
        this.getClassData(this.editData.classYear, this.editData.departmentId, this.editData.specialtyId);
        this.getSearchCourseData(this.editData.courseId);
        this.getSearchUserData(this.editData.teacherId);
        // this.getClassData(this.editData.departmentId,this.editData.specialtyId);
      },

      //显示新增界面
      handleAdd: function () {
        let newDate = new Date();
        this.addFormVisible = true;
        let val1 = this.newYear-1;
        let val2 = this.newYear+1;
        let semester;
        let schoolYear;
        let month = newDate.getMonth()+1;

        if(month >= 9){
          schoolYear = this.newYear+'-'+val2;
          semester = 1
        }else{
          schoolYear = val1+'-'+this.newYear;
          semester = 2
        }

        this.formData = {
          relevancyClass:{
            departmentId:'',
            specialtyId:'',
            year: '',
            classId:''
          },
          relevancyCourse:{
            departmentId:'',
            specialtyId:'',
            courseId:''
          },
          relevancyTeacher:{
            departmentId:'',
            teacherId:''
          },
          relevancyTime:{
            semester: semester,
            year:  schoolYear,
          },
          remark: ''
        };
      },

      //新增
      saveSubmit: function (num) {
        let user = sessionStorage.getItem('user');
        user = JSON.parse(user);
        let T_msg = '';
        let jsonStr = [];
        if (user) {
          if (num === 1) {
            this.$refs.formData.validate((valid) => {
              if (valid) {
                jsonStr = {
                  departmentName: '',
                  departmentId: '',
                  specialtyName: '',
                  specialtyId: '',
                  classYear: '',
                  className: '',
                  classId: '',
                  courseName: '',
                  courseId: '',
                  teacherName: '',
                  teacherId: '',
                  authorUserId: '',
                  year: '',
                  semester: '',
                  remark: '',
                };
                jsonStr.departmentName = this.departmentList.find(item => item.id === this.formData.relevancyClass.departmentId)['name'];
                jsonStr.departmentId = this.formData.relevancyClass.departmentId;
                jsonStr.specialtyName = this.specialtyList.find(item => item.id === this.formData.relevancyClass.specialtyId)['name'];
                jsonStr.specialtyId = this.formData.relevancyClass.specialtyId;
                jsonStr.classYear = this.formData.relevancyClass.year;
                jsonStr.className = this.classList.find(item => item.id === this.formData.relevancyClass.classId)['name'];
                jsonStr.classId = this.formData.relevancyClass.classId;

                jsonStr.courseName = this.courseList.find(item => item.id === this.formData.relevancyCourse.courseId)['name'];
                jsonStr.courseId = this.formData.relevancyCourse.courseId;

                jsonStr.teacherName = this.teacherList.find(item => item.id === this.formData.relevancyTeacher.teacherId)['name'];
                jsonStr.teacherId = this.formData.relevancyTeacher.teacherId;

                jsonStr.year = this.formData.relevancyTime.year;
                jsonStr.semester = this.formData.relevancyTime.semester;

                jsonStr.remark = this.formData.remark || '';
                jsonStr.authorUserId = user.id;

                this.saveData(jsonStr,'确认提交吗？',1);
              }
            });
          } else if (num === 2) {
            console.log(this.editData);
            jsonStr = Object.assign({}, this.editData);
            jsonStr.departmentName = this.departmentList.find(item => item.id === jsonStr.departmentId)['name'];
            jsonStr.specialtyName = this.specialtyList.find(item => item.id === jsonStr.specialtyId)['name'];
            jsonStr.className = this.classList.find(item => item.id === jsonStr.classId)['name'];
            jsonStr.courseName = this.courseList.find(item => item.id === jsonStr.courseId)['name'];
            jsonStr.teacherName = this.teacherList.find(item => item.id === jsonStr.teacherId)['name'];
            this.saveData(jsonStr,'确认修改吗？',2);
          }
        }
      },
      saveData: function(jsonStr,T_msg,saveType){
        this.$confirm(T_msg, '提示', {}).then(() => {
          this.saveLoading = true;
          this.saveLoading = false;
          console.log(jsonStr);
          saveRelevancyData(jsonStr).then((res) => {
            this.saveLoading = false;
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            if(saveType === 1){
              this.$refs['formData'].resetFields();
              this.addFormVisible = false;
			}else if(saveType === 2){
              this.$refs['editData'].resetFields();
              this.editFormVisible = false;
			}
            this.refreshFilters();
          });
        });
      },

      handleDel: function (index, row) {
        this.$confirm('确认删除该记录吗?', '提示', {
          type: 'warning'
        }).then(() => {
          this.listLoading = true;
          let para = { id: row.id };
          removeRelevancyData(para).then((res) => {
            this.listLoading = false;
            //NProgress.done();
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getData();
          });
        }).catch(() => {

        });
      },

      selsChange: function (sels) {
        this.sels = sels;
      },
    },
    mounted() {
      this.getData();
      this.getDepartmentData();
      this.getSpecialtyData();
      this.newYear = new Date().getFullYear();
    }
  }

</script>

<style scoped>

</style>